# -*- coding: utf-8 -*-

import requests
from bs4 import BeautifulSoup




#获取新浪页面示例

headers={"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"}
resp = requests.get(url="https://www.jd.com/",headers=headers)

with open("./jd.html","wb") as f:
    f.write(resp.content)

soup = BeautifulSoup(resp.content, "html.parser")
#获取头条新闻
tar_list = soup.select("li.more2_item")
for item in tar_list:
    print(item.text.strip())
    print(item.get('href'))
